<?php
if (!pdo_tableexists('goouc_class_stady')) {

    $sql = "
  CREATE TABLE IF NOT EXISTS `ims_goouc_class_stady`(
    		`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    		`weid` int(11) NOT NULL,
    		`sonid` int(11) DEFAULT NULL COMMENT '章节id',
    		`uid` int(11)  NOT NULL COMMENT '观看者的uid',
    		`create_time` int(11) NOT NULL COMMENT '订单创建时间',
    		PRIMARY KEY (`id`)
    )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '学习表';
    ";

    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_userlookm')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_userlookm`(
    		`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    		`weid` int(11) NOT NULL,
    		`uid` int(255) NOT NULL COMMENT '用户id',
    		`date` int(11) NOT NULL COMMENt '每月日期',
    		`time` int(11) NOT NULL COMMENT '本月观看时长',
    		PRIMARY KEY (`id`)
    )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '用户月观看视频时常';
    ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_city', 'qq')) {
    $sql = "ALTER TABLE ims_goouc_class_city ADD  `qq` int(15) DEFAULT NULL ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_city', 'tel')) {
    $sql = "ALTER TABLE ims_goouc_class_city ADD  `tel` varchar(20) DEFAULT NULL ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'xnum')) {
    $sql = "ALTER TABLE ims_goouc_class_son ADD  `xnum` int(11) DEFAULT 0 ";
    pdo_run($sql);
}
if (pdo_tableexists('goouc_class_setting')) {
    $sql = "DROP TABLE ims_goouc_class_setting";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_pcsetting')) {
    $sql = "CREATE TABLE IF NOT EXISTS `ims_goouc_class_pcsetting`(
        `id` int(10) NOT NULL AUTO_INCREMENT,
        `weid` int(11) not null,
        `title` varchar(255) NOT NULL,
        `pc_appid` varchar(255) DEFAULT NULL,
        `pc_secret` varchar(255) DEFAULT NULL,
        `icon` VARCHAR (255) DEFAULT NULL,
        `keywords` VARCHAR (255) DEFAULT NULL,
        `logo_title` VARCHAR (255) DEFAULT NULL,
        `logo` VARCHAR (255) DEFAULT NULL,
        `description` VARCHAR (255) DEFAULT NULL,
        `qq` int(15) DEFAULT NULL,
        `phone` int(20) DEFAULT NULL,
        `keepon` VARCHAR(255) DEFAULT NULL,
        `qrcode` VARCHAR(255) DEFAULT NULL,
        `xqrcode` varchar(255)  NULL DEFAULT '' COMMENT '网站小程序码' ,
        `address` varchar(255)  NULL DEFAULT '' ,
        PRIMARY KEY (`id`)
    )ENGINE=MyISAM DEFAULT CHARSET=utf8;COMMENT='PC网站设置表'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'old_money')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `old_money` decimal(10,2) DEFAULT 0.00";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'study_num')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `study_num` int(11) DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'free_num')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `free_num` int(11) DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'pc_description')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `pc_description` longtext DEFAULT NULL";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'free_son_id')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `free_son_id` VARCHAR(255) DEFAULT NULL";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'fic_pay_num')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `fic_pay_num` int(11) DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'fic_study_num')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `fic_study_num` int(11) DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'pctype')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `pctype` tinyint(1) DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_banner', 'position')) {
    $sql = "ALTER TABLE ims_goouc_class_banner ADD  `position` tinyint(4) DEFAULT 1";
    pdo_run($sql);
}

if (!pdo_fieldexists('goouc_class_usershar', 'cardnum')) {
    $sql = "ALTER TABLE ims_goouc_class_usershar ADD  `cardnum` int(11) DEFAULT 0 ";
    pdo_run($sql);
}
/*3-16*///更改用户表 nickname字段属性默认为空
if (pdo_fieldexists('goouc_class_user', 'nickname')) {
    $sql = "ALTER TABLE ims_goouc_class_user MODIFY COLUMN nickname varchar(255) NULL";
    pdo_run($sql);
}
//判断用户是不是新分享进来的新用户开关
if (!pdo_fieldexists('goouc_class_user', 'new_status')) {
    $sql = "ALTER TABLE ims_goouc_class_user ADD  `new_status` tinyint(1) DEFAULT 0 ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_user', 'session_key')) {
    $sql = "ALTER TABLE ims_goouc_class_user ADD  `session_key` varchar(255) DEFAULT NULL ";
    pdo_run($sql);
}

/*03-26  订单表*/
if (pdo_fieldexists('goouc_class_payment', 'compltet_time')) {
    $sql = "ALTER TABLE ims_goouc_class_payment MODIFY COLUMN compltet_time int(11) NULL";
    pdo_run($sql);
}
/*03-26  订单表*/

/*修改课程与年级为一对多*/
if (pdo_fieldexists('goouc_class_lesson', 'classid')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson MODIFY COLUMN classid varchar(255) NULL";
    pdo_run($sql);
}
// 用户可设置自己的年级
if (!pdo_fieldexists('goouc_class_user', 'classid')) {
    $sql = "ALTER TABLE ims_goouc_class_user ADD  `classid` int(11) DEFAULT NULL ";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_cardinfo')) {
    $sql = "
      CREATE TABLE IF NOT EXISTS `ims_goouc_class_cardinfo`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `cardnum` int(11) NOT NULL,
          `price` decimal(10,2) NOT NULL,
          `status` tinyint(1) DEFAULT 0,
          `createtime` int(11) NOT NULL,
          `order` int(4) DEFAULT 0,
          PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'cardnum')) {
    $sql = "ALTER TABLE ims_goouc_class_son ADD  `cardnum` int(11) DEFAULT 0 COMMENT '章节需要听课券张数' ";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_level')) {
    $sql = "CREATE TABLE IF NOT EXISTS `ims_goouc_class_level`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `name` varchar(255) NOT NULL,
          `time` int(11) NOT NULL,
          `status` tinyint(1) DEFAULT 0,
          `addtime` int(11) NOT NULL,
          `order` int(4) DEFAULT 0,
          PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
    pdo_run($sql);
}
if (pdo_tableexists('goouc_class_loginin')) {
    $sql = "DROP TABLE ims_goouc_class_loginin";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_signin')) {
    $sql = "CREATE TABLE IF NOT EXISTS `ims_goouc_class_signin`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `uid` int(255) NOT NULL COMMENT '用户签到标识',
            `num` int(11) DEFAULT 0 COMMENT '记录连续签到天数',
            `date` varchar(200) NOT NULL COMMENT '最近签到日期',
            `month` varchar(200) NOT NULL COMMENT '签到月份',
            `day` varchar(255) DEFAULT NULL COMMENT '当月签到汇总 数组形式',
            `status` tinyint(1) DEFAULT 0 COMMENT '领取每月奖励状态',
            PRIMARY KEY (`id`)
    )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '用户签到记录表';";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'desc')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `desc` varchar(255) DEFAULT NULL COMMENT '课程简介 区别于课程介绍' ";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_poster')) {
    $sql = "CREATE TABLE IF NOT EXISTS `ims_goouc_class_poster`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `title` varchar(255) NOT NULL COMMENT '分享海报的标题',
          `image` varchar(255) NOT NULL COMMENT '海报背景图 不能为空',
          `createtime` int(11) NOT NULL COMMENT '创建时间',
          `status` tinyint(1) DEFAULT 0,
          `order` int(4) DEFAULT 0,
          `position` tinyint(4) DEFAULT 1 COMMENT '背景图位置',
          PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_user', 'qrcode')) {
    $sql = "ALTER TABLE ims_goouc_class_user ADD  `qrcode` varchar(255) DEFAULT NULL COMMENT '用户个人二维码路径' ";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_os_order')) {
    $sql = " CREATE TABLE IF NOT EXISTS `ims_goouc_os_order`  (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `weid` int(11) NOT NULL,
        `type` int(11) NOT NULL COMMENT '购买类型 0课程报名 1课程 2单章节',
        `out_trade_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
        `userid` int(11) NOT NULL,
        `openid` varchar(255) NULL COMMENT '购买者的openid',
        `order_status` tinyint(1) NOT NULL COMMENT '订单状态 0未支付1已支付',
        `all_money` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '总金额',
        `true_money` decimal(10, 2) NOT NULL COMMENT '实付款',
        `createtime` int(11) NOT NULL,
        `paytime` int(11) NULL DEFAULT NULL,
        `msg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
        `dataid` int(11) NULL DEFAULT NULL,
        `transaction_sn` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '第三方流水号',
        `module` TINYINT(1) NOT NULL COMMENT '区分模块',
        PRIMARY KEY (`id`),
        KEY `idx_weid` (`weid`),
        KEY `idx_out_trade_no` (`out_trade_no`),
        KEY `idx_transaction_sn` (`transaction_sn`),
        KEY `idx_dataid` (`dataid`)
      ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_lesson', 'recommend')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `recommend` tinyint(4) DEFAULT 0 COMMENT '课程是否被推荐' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_class', 'classyear')) {
    $sql = "ALTER TABLE ims_goouc_class_class ADD  `classyear` tinyint(1) DEFAULT 1 COMMENT '默认学年为小学' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'vediotime')) {
    $sql = "ALTER TABLE ims_goouc_class_son ADD  `vediotime` decimal(20,2) DEFAULT '0.00' COMMENT '视频时长' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'coverurl')) {
    $sql = "ALTER TABLE ims_goouc_class_son ADD  `coverurl` varchar(255) DEFAULT NULL COMMENT '视频封面图片' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'updatestatus')) {
    $sql = "ALTER TABLE ims_goouc_class_son ADD  `updatestatus` tinyint(1) DEFAULT 0 COMMENT '是否更新过视频' ";
    pdo_run($sql);
}


/*2.0.1 banner图对应不同的年级*/
if (!pdo_fieldexists('goouc_class_banner', 'classid')) {
    $sql = "ALTER TABLE ims_goouc_class_banner ADD  `classid` int(11) DEFAULT 0 COMMENT '对应课程id' ";
    pdo_run($sql);
}
/*20.0.1 课程静态吗*/
if (!pdo_fieldexists('goouc_class_lesson', 'qrcode')) {
    $sql = "ALTER TABLE ims_goouc_class_lessond ADD  `qrcode` varchar(255) DEFAULT NULL COMMENT '每个课程的静态码' ";
    pdo_run($sql);
}
/*20.0.1 分型标题设置*/
if (!pdo_tableexists('goouc_class_shartitle')) {
    $sql = "CREATE TABLE IF NOT EXISTS `ims_goouc_class_shartitle`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `selected` varchar(255) DEFAULT NULL COMMENT '首页分享标题',
          `mine` varchar(255) DEFAULT NULL COMMENT '个人中心分享标题',
          `ranking` varchar(255) DEFAULT NULL COMMENT '排行榜分享标题',
          `ranking_detail` varchar(255) DEFAULT NULL COMMENT '完善信息分享标题',
          `myday` varchar(255) DEFAULT NULL COMMENT '签到分享标题',
          `rechange` varchar(255) DEFAULT NULL COMMENT '购买页面分享标题',
          `consultation` varchar(255) DEFAULT NULL COMMENT '咨询分享标题',
          PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
    pdo_run($sql);
}
/*2.0.1 海报增加对应等级*/
if (!pdo_fieldexists('goouc_class_poster', 'levelid')) {
    $sql = "ALTER TABLE ims_goouc_class_poster ADD  `levelid` int(11) DEFAULT 0 COMMENT '签到海报对应不同的背景图' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_poster_new', 'poster')) {
    $sql = "ALTER TABLE ims_goouc_class_poster_new ADD  `poster` varchar(500) DEFAULT NULL COMMENT '海报预览图' ";
    pdo_run($sql);
}
/*20.0.1 海报模板*/
if (!pdo_tableexists('goouc_class_shartitle')) {
    $sql = "CREATE TABLE IF NOT EXISTS `ims_goouc_class_type_status`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `name` varchar(255) NOT NULL ,
          `status` tinyint(1) DEFAULT 0 ,
          `position` tinyint(1) DEFAULT 1,
          `type` tinyint(1) NOT NULL,
          `image` varchar(255) NOT NULL,
          PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8";
    pdo_run($sql);
}
/*2.0.1 课程增加分享图片*/
if (!pdo_fieldexists('goouc_class_lesson', 'share_image')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `share_image` varchar(255) NOT NULL COMMENT '课程分享图片 不能为空' ";
    pdo_run($sql);
}


/*2.0.1 给章节表中 lessonid添加为普通索引*/
if (!pdo_indexexists('goouc_class_syslog', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_syslog` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_module', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_module` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_city', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_city` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_class', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_class` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_subject', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_subject` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_semester', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_semester` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_voidtype', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_voidtype` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_teacher', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_teacher` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_teacher', 'mobile')) {

    $sql = "ALTER TABLE ims_goouc_class_teacher ADD  `mobile` varchar(11)  NOT NULL DEFAULT '' COMMENT '手机号' ";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_lesson', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_lesson` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_lesson', 'idx_teacherid')) {
    $sql = "ALTER TABLE `ims_goouc_class_lesson` ADD INDEX `idx_teacherid` ( `teacherid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_lesson', 'idx_classid')) {
    $sql = "ALTER TABLE `ims_goouc_class_lesson` ADD INDEX `idx_classid` ( `classid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_lesson', 'idx_subjectid')) {
    $sql = "ALTER TABLE `ims_goouc_class_lesson` ADD INDEX `idx_subjectid` ( `subjectid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_son', 'idx_lessonid')) {
    $sql = "ALTER TABLE `ims_goouc_class_son` ADD INDEX `idx_lessonid` ( `lessonid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_phonecode', 'idx_phone')) {
    $sql = "ALTER TABLE `ims_goouc_class_phonecode` ADD INDEX `idx_phone` ( `phone` )";
    pdo_run($sql);
}

if (!pdo_indexexists('goouc_class_signin', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_signin` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_signin', 'idx_uid')) {
    $sql = "ALTER TABLE `ims_goouc_class_signin` ADD INDEX `idx_uid` ( `uid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_usercard', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_usercard` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_usercard', 'idx_uid')) {
    $sql = "ALTER TABLE `ims_goouc_class_usercard` ADD INDEX `idx_uid` ( `uid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_userlook', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_userlook` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_userlook', 'idx_uid')) {
    $sql = "ALTER TABLE `ims_goouc_class_userlook` ADD INDEX `idx_uid` ( `uid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_usershar', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_usershar` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_usershar', 'idx_uid')) {
    $sql = "ALTER TABLE `ims_goouc_class_usershar` ADD INDEX `idx_uid` ( `uid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_banner', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_banner` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_banner', 'idx_classid')) {
    $sql = "ALTER TABLE `ims_goouc_class_banner` ADD INDEX `idx_classid` ( `classid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_banner', 'idx_position')) {
    $sql = "ALTER TABLE `ims_goouc_class_banner` ADD INDEX `idx_position` ( `position` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_stady', 'idx_uid')) {
    $sql = "ALTER TABLE `ims_goouc_class_stady` ADD INDEX `idx_uid` ( `uid` )";
    pdo_run($sql);
}

if (!pdo_indexexists('goouc_class_userlookm', 'idx_uid')) {
    $sql = "ALTER TABLE `ims_goouc_class_userlookm` ADD INDEX `idx_uid` ( `uid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_userlookm', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_userlookm` ADD INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_userlookm', 'idx_date')) {
    $sql = "ALTER TABLE `ims_goouc_class_userlookm` ADD INDEX `idx_date` ( `date` )";
    pdo_run($sql);
}

//3.0更新内容

//添加用户表unionId字段
if (pdo_indexexists('goouc_class_user', 'unionId')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `unionId`";
    pdo_run($sql);
}

if (pdo_indexexists('goouc_class_user', 'idx_openid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `idx_openid`";
    pdo_run($sql);
}

if (pdo_indexexists('goouc_class_user', 'idx_phone')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `idx_phone`";
    pdo_run($sql);
}
if (pdo_indexexists('goouc_class_user', 'phone')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `phone`";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_user', 'idx_weid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` ADD  INDEX `idx_weid` ( `weid` )";
    pdo_run($sql);
}
if (pdo_indexexists('goouc_class_user', 'openid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `openid`";
    pdo_run($sql);
}
if (pdo_indexexists('goouc_class_user', 'pc_openid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `pc_openid`";
    pdo_run($sql);
}
if (pdo_indexexists('goouc_class_user', 'h5_openid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `h5_openid`";
    pdo_run($sql);
}
if (pdo_indexexists('goouc_class_user', 'idx_h5_openid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` DROP INDEX `idx_h5_openid`";
    pdo_run($sql);
}
//添加班型表  基本设置设置班型 与课程关联
if (!pdo_tableexists('goouc_class_classtype')) {
    $sql = "
    CREATE TABLE IF NOT EXISTS `ims_goouc_class_classtype`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `name` varchar(255) NOT NULL COMMENT '班型名称',
            `order` int(11) NOT NULL COMMENt '排序',
            `status` tinyint(1) NOT NULL COMMENT '状态',
            `addtime` int(11) NOT NULL COMMENT '添加时间',
            PRIMARY KEY (`id`)
        )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '班型设置表';
    ";
    pdo_run($sql);
}
//课程表添加classtypeid字段
if (!pdo_fieldexists('goouc_class_lesson', 'classtypeid')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `classtypeid` int(11)  DEFAULT NULL ;";
    pdo_run($sql);
}
//课程表添加is_only字段，判断是单节课程还是系列课程
if (!pdo_fieldexists('goouc_class_lesson', 'is_only')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `is_only` tinyint(1)  DEFAULT 2 ;";
    pdo_run($sql);
}

//课程表添加is_groupbuy  判断课程是否是可以团购的课程  2为非团购  1为团购课
if (!pdo_fieldexists('goouc_class_lesson', 'is_groupbuy')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `is_groupbuy` tinyint(1)  DEFAULT 2 ;";
    pdo_run($sql);
}
//添加助教老师id
if (!pdo_fieldexists('goouc_class_lesson', 'help_teacherid')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `help_teacherid` int(11)  NOT NULL;";
    pdo_run($sql);
}
//添加xhbnumber
if (!pdo_fieldexists('goouc_class_lesson', 'xhbnumber')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `xhbnumber` int(11)  NULL;";
    pdo_run($sql);
}
//添加paytype
if (!pdo_fieldexists('goouc_class_lesson', 'paytype')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `paytype` tinyint(1)  DEFAULT 2;";
    pdo_run($sql);
}
//修改desc字段为text
if (pdo_fieldexists('goouc_class_lesson', 'desc')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson MODIFY COLUMN `desc` text NULL";
    pdo_run($sql);
}
if (pdo_fieldexists('goouc_class_lesson', 'share_image')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson MODIFY COLUMN `share_image` varchar(255) DEFAULT NULL COMMENT '课程分享封面图 不能为空 必须有'";
    pdo_run($sql);
}
//放弃
//添加讲师头像以及讲师介绍
if (!pdo_fieldexists('goouc_class_teacher', 'headimg')) {
    $sql = 'ALTER TABLE ims_goouc_class_teacher ADD  `headimg` varchar(255) NOT NULL COMMENT "老师头像" ;';
    pdo_run($sql);
}
//添加讲师头像以及讲师介绍
if (!pdo_fieldexists('goouc_class_teacher', 'desc')) {
    $sql = 'ALTER TABLE ims_goouc_class_teacher ADD  `desc` text NOT NULL COMMENT "老师简介" ;';
    pdo_run($sql);
}
//晓禾币
if (pdo_fieldexists('goouc_class_cardinfo', 'cardnum')) {
    $sql = 'alter table ims_goouc_class_cardinfo drop column cardnum;
            alter table ims_goouc_class_cardinfo add `condition` int(11) NOT NULL COMMENT "兑课券使用限制";
    ';
    pdo_run($sql);
}
//兑课券添加解释说明
if (!pdo_fieldexists('goouc_class_cardinfo', 'desc')) {
    $sql = 'alter table ims_goouc_class_cardinfo add `desc` text DEFAULT NULL COMMENT "兑课券使用说明";';
    pdo_run($sql);
}
//兑课券添加解释说明
if (!pdo_fieldexists('goouc_class_cardinfo', 'need')) {
    $sql = 'alter table ims_goouc_class_cardinfo add `need` int(11) NOT NULL COMMENT "兑换兑课券需要的晓禾币数量";';
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_cardinfo', 'end_time')) {
    $sql = 'alter table ims_goouc_class_cardinfo add `end_time` int(11) NOT NULL COMMENT "兑课券有效期";';
    pdo_run($sql);
}
//新建海报表
if (!pdo_tableexists('goouc_class_poster_new')) {
    $sql = '
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_poster_new`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `bgimg` varchar(255) NOT NULL COMMENT \'海报背景图片\',
            `option` varchar(255) NOT NULL COMMENT \'海报选择开启的选项\',
            `qrcode_left_px` int(11) DEFAULT NULL COMMENT \'二维码左边距\',
            `qrcode_top_px` int(11) DEFAULT NULL COMMENT \'二维码上边距\',
            `qrcode_width_px` int(11) DEFAULT NULL COMMENT \'二维码宽度\',
            `qrcode_height_px` int(11) DEFAULT NULL COMMENT \'二维码高度\',
            `head_left_px` int(11) DEFAULT NULL COMMENT \'用户头像左边距\',
            `head_top_px` int(11) DEFAULT NULL COMMENT \'用户头像上边距\',
            `head_width_px` int(11) DEFAULT NULL COMMENT \'用户头像宽度\',
            `head_height_px` int(11) DEFAULT NULL COMMENT \'用户头像高度\',
            `nick_left_px` int(11) DEFAULT NULL COMMENT \'用户昵称左边距\',
            `nick_top_px` int(11) DEFAULT NULL COMMENT \'用户昵称上边距\',
            `nick_size_px` int(11) DEFAULT NULL COMMENT \'用户昵称字体大小\',
            `nick_font_color` varchar(7) DEFAULT NULL COMMENT \'用户昵称字体颜色\',
            `study_day_left_px` int(11) DEFAULT NULL COMMENT \'学习天数左边距\',
            `study_day_top_px` int(11) DEFAULT NULL COMMENT \'学习天数上边距\',
            `study_day_size_px` int(11) DEFAULT NULL COMMENT \'学习天数字体大小\',
            `study_day_font_color` varchar(7) DEFAULT NULL COMMENT \'学习天数字体颜色\',
            `date_left_px` int(11) DEFAULT NULL COMMENT \'当前日期左边距\',
            `date_top_px` int(11) DEFAULT NULL COMMENT \'当前日期上边距\',
            `date_size_px` int(11) DEFAULT NULL COMMENT \'当前日期字体提大小\',
            `date_font_color` varchar(7) DEFAULT NULL COMMENT \'当前日期字体颜色\',
            `status` tinyint(1) NOT NULL COMMENT \'状态 1 启用 2 未启用\',
            `addtime` int(11) NOT NULL COMMENT \'添加时间\',
            `poster`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT \'\' COMMENT \'海报预览图\' ,
            PRIMARY KEY (`id`)
        )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = \'海报设置表\';
    ';
    pdo_run($sql);
}
//用户报名课程 记录表
if (!pdo_tableexists('goouc_class_user_signup')) {
    $sql = '
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_user_signup`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `uid` int(11) NOT NULL COMMENT \'报名用户id\',
            `lessonid` int(11) NOT NULL COMMENT \'报名课程id\',
            `type` tinyint(1) DEFAULT 2 COMMENT \'2免费 3晓禾币 4全款付费 5团购付费\',
            `xhbnumber` int(11) DEFAULT 0 COMMENT \'用户消耗晓禾币数量\',
            `pay_money` decimal(10,2) DEFAULT \'0.00\' COMMENT \'用户全款购买的价格\',
            `old_money` decimal(10,2) DEFAULT \'0.00\' COMMENT \'团购价格\',
            `createtime` int(11) NOT NULL COMMENT \'报名时间\',
            PRIMARY KEY (`id`),
            KEY `idx_uid` (`uid`),
            KEY `idx_lessonid` (`lessonid`)
        )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = \'用户报名课程记录表 记录用户报名的免费课程 扣除晓禾币后报名的课程 购买的完成的课程\';
    ';
    pdo_run($sql);
}
//记录用户任务表 没想好怎么弄

//添加课程开始时间 然后根据视频时长计算出结束时间
if (!pdo_fieldexists('goouc_class_son', 'starttime')) {
    $sql = "alter table ims_goouc_class_son add `starttime` int(11) NOT NULL COMMENT '章节开课时间'";
    pdo_run($sql);
}
//增加用户自定义头像字段
if (!pdo_fieldexists('goouc_class_user', 'myheaderimg')) {
    $sql = "alter table ims_goouc_class_user add `myheaderimg` varchar(255) DEFAULT NULL COMMENT '用户自定义头像'";
    pdo_run($sql);
}
//增加兑课券表
if (!pdo_tableexists('goouc_class_user_exchange')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_user_exchange`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `uid` int(11) NOT NULL COMMENT '用户id',
            `cid` int(11) NOT NULL COMMENT '兑课券id',
            `status` tinyint(1) NOT NULL COMMENT '使用状态状态 1已使用 2 未使用',
            `year` int(11) NOT NULL COMMENT '兑换年份',
            `addtime` int(11) NOT NULL COMMENT '兑换时间',
            PRIMARY KEY (`id`)
        )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '用户兑课券表';
    ";
    pdo_run($sql);
}
//用户拼团
if (!pdo_tableexists('goouc_class_user_group')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_user_group`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `uid` int(11) NOT NULL COMMENT '用户id',
            `lessonid` int(11) NOT NULL COMMENT '课程id',
            `groupnum` int(11) DEFAULT 1 COMMENT '团人数',
            `status` tinyint(1) DEFAULT 2 COMMENT '团状态 默认1 拼团成功 2 拼团未完成 3团已过期',
            `createtime` int(11)  NOT NULL COMMENT '开团时间',
            PRIMARY KEY (`id`)
        )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '用户开团表';
    ";
    pdo_run($sql);
}
//用户参团表
if (!pdo_tableexists('goouc_class_user_group_info')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_user_group_info`(
            `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
            `weid` int(11) NOT NULL,
            `groupid` int(11) NOT NULL COMMENT '团ID',
            `uid` int(11) NOT NULL COMMENT '用户id',
            `isgrouper` tinyint(1) DEFAULT 1 COMMENT '默认是团长',
            `lessonid` int(11) NOT NULL COMMENT '课程id',
            `createtime` int(11)  NOT NULL COMMENT '参团时间',
            `out_trade_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 
            `refund_status`  tinyint(1) NULL DEFAULT 2 COMMENT '1:已退款   2：未退款' ,
            `refund_time`  int(11) NULL DEFAULT 0 COMMENT '退款时间' ,
            PRIMARY KEY (`id`)
        )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = '用户参团表';
    ";
    pdo_run($sql);
}
//订单表
if (!pdo_tableexists('goouc_class_order')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_order`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `type` int(11) NOT NULL COMMENT '购买类型 1原价购买 2开团购买 3参团购买 4 使用兑课券购买',
          `out_trade_no` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
          `userid` int(11) NOT NULL,
          `openid` varchar(255) NULL COMMENT '购买者的openid',
          `order_status` tinyint(1) NOT NULL COMMENT '订单状态 0未支付1已支付2已退款',
          `all_money` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '总金额',
          `true_money` decimal(10, 2) NOT NULL COMMENT '实付款',
          `createtime` int(11) NOT NULL,
          `paytime` int(11) NULL DEFAULT NULL,
          `msg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
          `dataid` int(11) NULL DEFAULT NULL,
          `usercardid` int(11) NULL DEFAULT NULL,
          `groupid` int(11) NULL DEFAULT 0 COMMENT '0 开团  其他为参团id',
          `transaction_sn` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '第三方流水号',
          `module` TINYINT(1) NOT NULL COMMENT '区分模块',
          `refundtime`  int(11) NULL DEFAULT 0 COMMENT '退款时间' ,
          PRIMARY KEY (`id`),
          KEY `idx_weid` (`weid`),
          KEY `idx_out_trade_no` (`out_trade_no`),
          KEY `idx_transaction_sn` (`transaction_sn`),
          KEY `idx_dataid` (`dataid`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_order', 'refundtime')) {
    $sql = "alter table ims_goouc_class_order add `refundtime` int(11) DEFAULT 0 COMMENT '退款时间'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_user_group_info', 'refund_status')) {
    $sql = "alter table ims_goouc_class_user_group_info add `refund_status`  tinyint(1) NULL DEFAULT 2 COMMENT '1:已退款   2：未退款'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_user_group', 'refund_status')) {
    $sql = "alter table ims_goouc_class_user_group add `refund_status`  tinyint(1) NULL DEFAULT 2 COMMENT '1:已退款   2：未退款'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_user_group_info', 'refund_time')) {
    $sql = "alter table ims_goouc_class_user_group_info add `refund_time`  int(11) NULL DEFAULT 0 COMMENT '退款时间'";
    pdo_run($sql);
}
//回放记录表
if (!pdo_fieldexists('goouc_class_userlook', 'num')) {
    $sql = "alter table ims_goouc_class_userlook add `num` int(11) DEFAULT 0 COMMENT '本周发放晓禾币次数'";
    pdo_run($sql);
}

if (!pdo_tableexists('goouc_class_user_study_speed')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_user_study_speed`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `uid` int(11) NOT NULL,
          `lessonid` int(11) NOT NULL,
          `sonid` int(11) NOT null,
          `speed` int(11) NOT NULL COMMENT '当前章节学习到的进度',
          `study_time` int(11) NOT NULL,
          PRIMARY KEY (`id`),
          KEY `idx_weid` (`weid`),
          KEY `idx_uid` (`uid`),
          KEY `idx_lessonid` (`lessonid`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    ";
    pdo_run($sql);
}


if (!pdo_tableexists('goouc_class_live_message')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_live_message`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `uid` int(11) NOT NULL,
          `sonid` int(11) NOT NULL,
          `content` text  CHARACTER SET utf8mb4 DEFAULT NULL,
          `type` tinyint(1) DEFAULT 0,
          `name` text CHARACTER SET utf8mb4 DEFAULT NULL,
          `size` varchar(255) DEFAULT NULL,
          `createtime` int(11) NOT null,
          PRIMARY KEY (`id`),
          KEY `idx_weid` (`weid`),
          KEY `idx_uid` (`uid`),
          KEY `idx_sonid` (`sonid`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    ";
    pdo_run($sql);
}

if (!pdo_fieldexists('goouc_class_live_message', 'type')) {
    $sql = "alter table ims_goouc_class_live_message add `type` tinyint(1) DEFAULT 0 ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_live_message', 'name')) {
    $sql = "alter table ims_goouc_class_live_message add `name` text CHARACTER SET utf8mb4 DEFAULT NULL ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_live_message', 'size')) {
    $sql = "alter table ims_goouc_class_live_message add `size` varchar(255) DEFAULT NULL ";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_user_study_sign')) {
    $sql = "
        CREATE TABLE IF NOT EXISTS `ims_goouc_class_user_study_sign`  (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `weid` int(11) NOT NULL,
          `uid` int(11) NOT NULL,
          `sonid` int(11) NOT NULL,
          `createtime` int(11) NOT null,
          `status` tinyint(1) DEFAULT 2,
          PRIMARY KEY (`id`),
          KEY `idx_weid` (`weid`),
          KEY `idx_uid` (`uid`),
          KEY `idx_sonid` (`sonid`)
        ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    ";
    pdo_run($sql);
}

if (!pdo_fieldexists('goouc_class_son', 'sontype')) {
    $sql = "alter table ims_goouc_class_son add `sontype` tinyint(1) DEFAULT 2 COMMENT '默认为录播课程,1为直播课程; 2 为录播课程; 4伪直播; 3：真直播直播中; 5真直播直播结束'";
    pdo_run($sql);
}

/*为PC端创建的字段*/
if (!pdo_fieldexists('goouc_class_pcsetting', 'xqrcode')) {
    $sql = "alter table ims_goouc_class_pcsetting add `xqrcode` varchar(255) DEFAULT NULL COMMENT '网站小程序码'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_pcsetting', 'address')) {
    $sql = "alter table ims_goouc_class_pcsetting add `address` varchar(255) DEFAULT NULL COMMENT '地址'";
    pdo_run($sql);
}
/*为PC端创建的字段*/


/**
 * 更改banner对应年级为多选
 */
if (pdo_fieldexists('goouc_class_banner', 'classid')) {
    $sql = "ALTER TABLE ims_goouc_class_banner MODIFY COLUMN classid varchar(255) NULL";
    pdo_run($sql);
}
/**
 *PC端首页分类
 */

if (!pdo_fieldexists('goouc_class_lesson', 'pctype')) {
    $sql = "alter table ims_goouc_class_lesson add `pctype` tinyint(1) DEFAULT 1 COMMENT 'PC首页分类'";
    pdo_run($sql);
}

/**
 * 增加H5接口效验token
 */
if (!pdo_tableexists('goouc_class_user_token')) {
    $sql = "CREATE TABLE `ims_goouc_class_user_token` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `weid` int(11) NOT NULL,
    `uid` int(11) NOT NULL,
    `token` varchar(255) NOT NULL COMMENT 'token',
    `createtime` int(11) NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户访问接口token表';";
    pdo_run($sql);
}

/**
 *重要修改
 */


/**
 * 增加son数据表字段  直播有关的
 */
if (!pdo_fieldexists('goouc_class_son', 'live_url')) {
    $sql = "alter table ims_goouc_class_son add `live_url` text  NULL COMMENT '直播推流地址'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'broad_url')) {
    $sql = "alter table ims_goouc_class_son add `broad_url` text  NULL COMMENT '直播播放地址'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'create_url_time')) {
    $sql = "alter table ims_goouc_class_son add `create_url_time` INT(11)  NULL COMMENT '创建url时间'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'url_time')) {
    $sql = "alter table ims_goouc_class_son add `url_time` VARCHAR(255)  NULL COMMENT 'url有效期'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'vodtranscodegroupid')) {
    $sql = "alter table ims_goouc_class_son add `vodtranscodegroupid` VARCHAR(255)  NULL COMMENT '直播转点播的转码模板id'";
    pdo_run($sql);
}

/*
 * 咨询改为文章
 * */
if (!pdo_tableexists('goouc_class_category')) {
    $sql = 'CREATE TABLE IF NOT EXISTS `ims_goouc_class_category` (
			  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
			  `weid` int(11) NOT NULL ,
			  `name` varchar(255) NOT NULL ,
			  `order` int(11) DEFAULT 0 ,
			  `status` tinyint(1) DEFAULT 0,
			  `createtime` int(10) NOT NULL ,	
			  PRIMARY KEY (`id`),
        	  KEY `idx_weid` (`weid`)
		) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=\'文章分类\';';
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_article')) {
    $sql = 'CREATE TABLE IF NOT EXISTS `ims_goouc_class_article` (
			  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
			  `weid` int(11) NOT NULL ,
			  `cid` int(11) NOT NULL ,
			  `title` VARCHAR(255) NOT NULL,
			  `content` text DEFAULT NULL,
			  `image` VARCHAR(255) DEFAULT NULL,
			  `looknum` int(11) DEFAULT 0,
			  `order` int(11) DEFAULT 0 ,
			  `status` tinyint(1) DEFAULT 0,
			  `recommond` tinyint(1) DEFAULT 0,
			  `createtime` int(10) NOT NULL ,	
			  PRIMARY KEY (`id`),
        	  KEY `idx_weid` (`weid`)
		) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=\'文章列表\';';
    pdo_run($sql);
}


/*1.20  更新线下课程视频*/
if (!pdo_fieldexists('goouc_class_lesson', 'is_underline')) {
    $sql = "ALTER TABLE ims_goouc_class_lesson ADD  `is_underline` TINYINT(1) DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_lesson_underline_student')) {
    $sql = 'CREATE TABLE IF NOT EXISTS `ims_goouc_class_lesson_underline_student`(
       `id` int(11) NOT NULL AUTO_INCREMENT,
       `weid` int(11) not null,
       `phone` varchar(11) NOT NULL,
       `username` varchar(32) NOT NULL,
       `lesson_id` int(11) NOT NULL COMMENT "课程id",
       `createtime` int(11) NOT NULL,
       PRIMARY KEY (`id`),
       KEY `idx_phone` (`phone`)
    )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT = "线下学员名单";';
    pdo_run($sql);
}

/*习题*/
if (!pdo_tableexists('goouc_class_practice')) {
    $sql = "CREATE TABLE `ims_goouc_class_practice` (
            `id`  bigint(20) NOT NULL AUTO_INCREMENT ,
            `weid`  int(11) NULL DEFAULT 0 COMMENT '店铺id' ,
            `lessonid`  int(11) NULL DEFAULT 0 COMMENT '课程id' ,
            `sonid`  int(11) NULL DEFAULT 0 COMMENT '章节id' ,
            `type`  int(11) NULL DEFAULT 0 COMMENT '题型：1 判断 2单选 3多选 4 填空  5 解答' ,
            `question`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '问题' ,         
            `thumb`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '问题图片' ,
            `answer`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '答案' ,
            `items`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '所有选项' ,
            `img_items`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '所有图片选项' ,
            `analysis`  text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '讲解' ,
            `fansnum`  int(11) NULL DEFAULT 0 COMMENT '多少人做过' ,
            `correctnum`  int(11) NULL DEFAULT 0 COMMENT '多少人正确' ,
            `status`  tinyint(1) NULL DEFAULT 1 COMMENT '1:显示  0：隐藏' ,
            `isimg`  tinyint(1) NULL DEFAULT 0 COMMENT '0:文本  1：图片' ,
            `is_delete`  tinyint(1) NULL DEFAULT 1 COMMENT '1:使用 2：删除' ,
            `sort`  int(11) NULL DEFAULT 0 COMMENT '排序' ,
            PRIMARY KEY (`id`),
            INDEX `idx_type` (`type`) USING BTREE ,
            INDEX `idx_weid` (`weid`) USING BTREE 
            )
            ENGINE=InnoDB
            DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
            COMMENT='试题列表'
            AUTO_INCREMENT=1
            ROW_FORMAT=COMPACT
            ;";
    pdo_run($sql);
}
//做题记录
if (!pdo_tableexists('goouc_class_practice_record')) {
    $sql = "CREATE TABLE `ims_goouc_class_practice_record` (
            `id`  int(11) NOT NULL AUTO_INCREMENT ,
            `weid`  int(11) NOT NULL DEFAULT 0 COMMENT '店铺id' ,
            `uid`  int(11) NOT NULL DEFAULT 0 COMMENT '会员id' ,
            `lessonid`  int(11) NOT NULL DEFAULT 0 COMMENT '课程id' ,
            `sonid`  int(11) NOT NULL DEFAULT 0 COMMENT '章节id' ,
            `record`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '答题记录' ,
            `createtime`  int(11) NOT NULL DEFAULT 0 COMMENT '时间' ,
            `status`  tinyint(1) NULL DEFAULT 1 COMMENT '1:可以使用   2：隐藏' ,
            `updatetime`  int(11) NULL DEFAULT 0 COMMENT '更新时间' ,
            PRIMARY KEY (`id`),       
            INDEX `idx_weid` (`weid`) USING BTREE,
            INDEX `idx_lessonid` (`lessonid`) USING BTREE ,
            INDEX `idx_sonid` (`sonid`) USING BTREE 
            )
            ENGINE=InnoDB
            DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
            COMMENT='答题记录'
            AUTO_INCREMENT=1
            ROW_FORMAT=COMPACT
            ;";
    pdo_run($sql);
};

//错题记录
if (!pdo_tableexists('goouc_class_practice_false_record')) {
    $sql = "CREATE TABLE `ims_goouc_class_practice_false_record` (
            `id`  int(11) NOT NULL AUTO_INCREMENT ,
            `weid`  int(11) NOT NULL DEFAULT 0 COMMENT '店铺id' ,
            `uid`  int(11) NOT NULL DEFAULT 0 COMMENT '会员id' ,
            `lessonid`  int(11) NOT NULL DEFAULT 0 COMMENT '课程id' ,
            `sonid`  int(11) NOT NULL DEFAULT 0 COMMENT '章节id' ,
            `practiceid`  int(11) NOT NULL DEFAULT 0 COMMENT '习题id' ,
            `answer`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '正确答案' ,
            `useranswer`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '学员答案' ,
            `createtime`  int(11) NOT NULL DEFAULT 0 COMMENT '时间' ,
            `is_delete`  tinyint(1) NOT NULL DEFAULT 1 COMMENT '1:使用  2：删除' ,
            PRIMARY KEY (`id`),
            INDEX `idx_weid` (`weid`) USING BTREE 
            )
            ENGINE=InnoDB
            DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
            COMMENT='错题本'
            AUTO_INCREMENT=1
            ROW_FORMAT=COMPACT
            ;";
    pdo_run($sql);
}

//星星记录
if (!pdo_tableexists('goouc_class_user_star')) {
    $sql = "CREATE TABLE `ims_goouc_class_user_star` (
            `id`  int(11) NOT NULL AUTO_INCREMENT ,
            `weid`  int(11) NULL DEFAULT 0 COMMENT '店铺id' ,
            `uid`  int(11) NOT NULL DEFAULT 0 COMMENT '会员id' ,
            `lessonid`  int(11) NOT NULL DEFAULT 0 COMMENT '课程id' ,
            `sonid`  int(11) NOT NULL DEFAULT 0 COMMENT '章节id' ,
            `num`  int(1) NOT NULL DEFAULT 0 COMMENT '星星数量' ,
            `createtime`  int(11) NOT NULL DEFAULT 0 ,
             `status`  tinyint(1) NULL DEFAULT 1 COMMENT '1:可以使用   2：隐藏' ,
            PRIMARY KEY (`id`),
            INDEX `id_weid` (`weid`) USING BTREE 
            )
            ENGINE=InnoDB
            DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
            COMMENT='会员获取星星数量记录表'
            AUTO_INCREMENT=1
            ROW_FORMAT=COMPACT
            ;";
    pdo_run($sql);
}

//教师端修改表
if (!pdo_fieldexists('goouc_class_user', 'teacherid')) {
    $sql = "ALTER TABLE `ims_goouc_class_user` ADD `teacherid` int(11) NULL DEFAULT 0 COMMENT '教师表关联id' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_teacher', 'mobile')) {
    $sql = "ALTER TABLE ims_goouc_class_teacher ADD  `mobile` varchar(11)  NOT NULL DEFAULT '' COMMENT '手机号' ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_user', 'type')) {
    $sql = "ALTER TABLE ims_goouc_class_user ADD  `type` tinyint(1) NULL DEFAULT 1 COMMENT '1：学生   2：老师'  ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_practice_record', 'type')) {
    $sql = "ALTER TABLE ims_goouc_class_practice_record ADD  `updatetime`  int(11) NULL DEFAULT 0 COMMENT '更新时间' ";
    pdo_run($sql);
}

if (!pdo_tableexists('goouc_class_teacher_task')) {
    $sql = "CREATE TABLE `ims_goouc_class_teacher_task` (
            `id`  int(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
            `weid`  int(11) NOT NULL DEFAULT 0 COMMENT '店铺id' ,
            `uid`  int(11) NOT NULL DEFAULT 0 COMMENT '教师uid' ,
            `teacherid`  int(11) NOT NULL DEFAULT 0 COMMENT '教师表uid' ,
            `lessonid`  int(11) NOT NULL DEFAULT 0 COMMENT '课程id' ,
            `sonid`  varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '章节id序列' ,
            `studentid`  varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '学生id序列' ,
            `totalstudent`  int(8) NOT NULL DEFAULT 0 COMMENT '总学生数' ,
            `totalson`  int(3) NOT NULL DEFAULT 0 COMMENT '总章节数' ,
            `endtime`  int(11) NOT NULL DEFAULT 0 COMMENT '截止时间' ,
            `title`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '作业标题' ,
            `message`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文本消息' ,
            `createtime`  int(11) NOT NULL DEFAULT 0 COMMENT '创建时间' ,
            `datetime`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '日期' ,
            PRIMARY KEY (`id`),
            INDEX `idx_weid` (`weid`) USING BTREE ,
            INDEX `idx_lessonid` (`lessonid`) USING BTREE ,
            INDEX `idx_uid` (`uid`) USING BTREE 
            )
            ENGINE=MyISAM
            DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
            AUTO_INCREMENT=2
            CHECKSUM=0
            ROW_FORMAT=DYNAMIC
            DELAY_KEY_WRITE=0
            ;";
    pdo_run($sql);
}

//直播录制视频
if (!pdo_tableexists('goouc_class_live_record')) {
    $sql = "
        CREATE TABLE `ims_goouc_class_live_record` (
            `id`  int(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
            `sonid`  int(11) NOT NULL DEFAULT 0 COMMENT '章节id' ,
            `stream`  varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '直播码' ,
            `app`  varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '频道名' ,
            `weid`  int(11) NULL DEFAULT 0 COMMENT '店铺id' ,
            `ctime`  int(11) NOT NULL DEFAULT 0 COMMENT '创建时间' ,
            `utime`  int(11) NOT NULL DEFAULT 0 COMMENT '修改时间' ,
            `flv`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' ,
            `mp4`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' ,
            `m3u8`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' ,
            `duration`  int(11) NOT NULL DEFAULT 0 COMMENT '录制时间 秒' ,
            `start_time`  int(11) NOT NULL DEFAULT 0 COMMENT '开始时间' ,
            `stop_time`  int(11) NOT NULL DEFAULT 0 COMMENT '结束时间' ,
            `domain`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '播流域名' ,
            PRIMARY KEY (`id`),
            INDEX `idx_sonid` (`sonid`) USING BTREE ,
            INDEX `idx_weid` (`weid`) USING BTREE 
            )
            ENGINE=InnoDB
            DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci
            COMMENT='直播录制视频'
            AUTO_INCREMENT=1
            ROW_FORMAT=COMPACT
            ; 
    ";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'live_url')) {
    $sql = "alter table ims_goouc_class_son add `live_url` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '推流地址'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'broad_url')) {
    $sql = "alter table ims_goouc_class_son add `broad_url` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '播流地址'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'url_time')) {
    $sql = "alter table ims_goouc_class_son add `url_time` int(11) NULL DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'create_url_time')) {
    $sql = "alter table ims_goouc_class_son add `create_url_time` int(11) NULL DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_tableexists('goouc_class_user_son_time')) {
    $sql = "CREATE TABLE `ims_goouc_class_user_son_time` (
            `id`  int(11) NOT NULL AUTO_INCREMENT ,
            `weid`  int(11) NOT NULL DEFAULT 0 COMMENT '店铺id' ,
            `uid`  int(11) NOT NULL DEFAULT 0 COMMENT '用户uid' ,
            `sonid`  int(11) NOT NULL DEFAULT 0 COMMENT '章节id' ,
            `time`  int(11) NOT NULL DEFAULT 0 COMMENT '观看时长' ,
            `createtime`  int(11) NOT NULL DEFAULT 0 COMMENT '时间' ,
            PRIMARY KEY (`id`),
            INDEX `idx_weid` (`weid`) USING BTREE 
            )
            ENGINE=InnoDB
            DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
            COMMENT='用户学习时长记录表'
            AUTO_INCREMENT=1
            ROW_FORMAT=DYNAMIC
            ;";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_practice_record', 'idx_lessonid')) {
    $sql = "ALTER TABLE `ims_goouc_class_practice_record` ADD INDEX `idx_lessonid` ( `lessonid` )";
    pdo_run($sql);
}
if (!pdo_indexexists('goouc_class_practice_record', 'idx_sonid')) {
    $sql = "ALTER TABLE `ims_goouc_class_practice_record` ADD INDEX `idx_sonid` ( `sonid` )";
    pdo_run($sql);
}
//classin
if (!pdo_fieldexists('goouc_class_son', 'classin_url')) {
    $sql = "alter table ims_goouc_class_son add `classin_url` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'classin播流地址'";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'cl_courseid')) {
    $sql = "alter table ims_goouc_class_son add `cl_courseid` int(11) NULL DEFAULT 0";
    pdo_run($sql);
}
if (!pdo_fieldexists('goouc_class_son', 'cl_classid')) {
    $sql = "alter table ims_goouc_class_son add `cl_classid` int(11) NULL DEFAULT 0";
    pdo_run($sql);
}
?>
